package org.neuedu.ssmp.crm.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.neuedu.ssmp.crm.entity.Chances;
import org.neuedu.ssmp.crm.entity.ChancesPlan;
import org.neuedu.ssmp.crm.entity.Orders;
import org.neuedu.ssmp.crm.entity.vo.ResponseEntity;
import org.neuedu.ssmp.crm.service.IChancesPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: Administrator
 * @Date: 2019/12/18 11:11
 * @Description:
 */
@RestController
@RequestMapping("/plan")
@Slf4j
public class ChancesPlanController {
    @Autowired
    private IChancesPlanService planService;

    @GetMapping("list")
    public List<ChancesPlan> plans(@RequestParam Integer id){
        return planService.lists(id);
    }
    @PostMapping("add")
    public ResponseEntity add(@RequestBody ChancesPlan chancesPlan){
        planService.save(chancesPlan);
        return ResponseEntity.ok("成功");
    }
    @PostMapping("edit")
    public ResponseEntity edit(@RequestParam String effect,@RequestParam Integer id, @RequestParam String plan) {
        UpdateWrapper<ChancesPlan> wrapper = new UpdateWrapper<>();
        wrapper.set("effect",effect).eq("chances_id",id).eq("plan_name",plan);
        planService.update(wrapper);
        return ResponseEntity.ok("成功");
    }
    @PostMapping("edit1")
        public ResponseEntity edit1(@RequestParam Integer ids, @RequestParam String plan ,@RequestParam String id) {
        UpdateWrapper<ChancesPlan> wrapper = new UpdateWrapper<>();
        wrapper.set("plan_name",plan).eq("id",ids).eq("chances_id",id);
        planService.update(wrapper);
        return ResponseEntity.ok("成功");
    }

    @DeleteMapping("delete")
    public ResponseEntity delete(Integer id){
        if (planService.removeById(id)){
            return ResponseEntity.ok("删除计划成功");
        }
        return ResponseEntity.error("出错了");
    }
}
